<?php
    include_once "conn.php";
    //读取用户名
    $name = $_COOKIE['name'];

    //比较密码
    if(isset($_POST['password']) && isset($_POST['password2'])){
        $password = $_POST['password'];
        $password2 = $_POST['password2'];
        if($password == $password2){
            $new = md5($password);
            $sql = "update `user` set `password` = '".$new."' where `name` = '".$name."'";
            $result = mysqli_query($conn,$sql);
            if($result){
                setcookie('password',$new);
                echo "修改成功";
            }else{
                echo "修改失败";
            }
        }else{
            echo "两次输入不一致";
        }
    }
?>
<html>
    <head>
        <title>后台管理系统-修改密码</title>
        <meta charset="utf-8">
    </head>
    <body>
    <form method='POST' action="password.php">
            <center><h1>PHPAdmin后台管理系统</h1></center>
            <center>原始账号：<input type='text' name='account' value='<?php echo $name;?>' disabled></center>
            <center>新的密码：<input type='text' name='password'></center>
            <center>确认密码：<input type='text' name='password2'></center>
            <center><input type='submit' name='change' value='修改密码'</center>
        </form>
    </body>
</html>